package org.itboys.mobile.service.mongo.weixin;


import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.entity.mongo.project.ZhongBaoProject;
import org.itboys.mobile.entity.mongo.project.ZhongBaoProjectImage;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：众包_微信_项目_图片_service
 */
@Service
public class ZhongBaoWeiXinProjectImageService extends BaseMongoService<ZhongBaoProjectImage> {



    @Resource(name = "mobileDs")
    private MongoDataSource mobileDataSource;
    @Override
    protected MongoDataSource getMongoDataSource() {
        return mobileDataSource;
    }

    @Override
    protected Class<ZhongBaoProjectImage> getEntityClass() {
        return ZhongBaoProjectImage.class;
    }

    /**
     * 保持项目图片
     * @param projectId
     * @param images
     */
    public  void saveImages(Long projectId,List<String> images){
        if(ListUtil.isNull(images)){
            return;
        }
        Map<String,Object> param = new HashMap<String,Object>();
        //删除原有的项目图片
        param.clear();
        param.put("isDeleted", SundayCommonConstants.NO);
        param.put("projectId",projectId);
        super.delete(param);
        List<ZhongBaoProjectImage> projectImages=new ArrayList<>();
        for(String image:images){
            projectImages.add(new ZhongBaoProjectImage(projectId,image));
        }
        super.batchSaveWithoutLogin(projectImages);

    }
    /**
     * 获取项目图片
     */





}
